/*
 * @(#)Env.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.ldap.core;

import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.Utility;

/**
     Env.java
     
     This class is responsible for Environment of LDAPImportOprator operation.
     
     @author Charlie  
     @company          DCIVision Limited
     @creation date    14/12/2004
     @version          $Revision: 1.7 $
 */
public class Env {
	//LDAP parameter constants
	public static final String LDAP_HOST="ldap.host";
	public static final String LDAP_MGRDN="ldap.mgrDN";
	public static final String LDAP_MGRPW="ldap.mgrPW";
	public static final String LDAP_SEARCHBASE="ldap.searchBase";
	public static final String LDAP_FILTER="ldap.filter";
	public static final String LDAP_ENTRYDN="ldap.entryDN";
	public static final String LDAP_AUTHENTICATION="ldap.authentication";
	//user account structure constants
	public static final String LDAP_STAFF_CODE="ldap.staff.code";
	public static final String LDAP_ACCOUNT_FIRSTNAME="ldap.user.firstName";
	public static final String LDAP_ACCOUNT_LASTNAME="ldap.user.lastName";
	public static final String LDAP_ACCOUNT_FULLNAME="ldap.user.fullName";
	public static final String LDAP_ACCOUNT_EMAIL="ldap.user.email";
	public static final String LDAP_ACCOUNT_LOGINNAME="ldap.user.loginName";
	public static final String LDAP_ACCOUNT_LOGINPASSWORD="ldap.user.loginPassword";
	public static final String LDAP_ACCOUNT_MAXATTEMPT="ldap.user.max_attempt";
	public static final String LDAP_ACCOUNT_EXPIRYDAY="ldap.user.expiry_day";
	public static final String LDAP_ACCOUNT_STATUS="ldap.user.status";
	public static final String LDAP_ACCOUNT_PREFERENCE="ldap.user.preference";
	public static final String LDAP_ACCOUNT_LANGUAGE="ldap.user.language";

	/**
	 * Constructor
	 *
	 */

	public Env(){		
		//ldap parameter initialization		
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_HOST)!=null)
			this.setService(SystemParameterFactory.getSystemParameter(Env.LDAP_HOST));					
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_MGRDN)!=null)
			this.setMgr_DN(SystemParameterFactory.getSystemParameter(Env.LDAP_MGRDN));		
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_MGRPW)!=null)
			this.setMgr_PW(SystemParameterFactory.getSystemParameter(Env.LDAP_MGRPW));
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_SEARCHBASE)!=null)
			this.setSearchbase(SystemParameterFactory.getSystemParameter(Env.LDAP_SEARCHBASE));	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_FILTER)!=null)
			this.setFilter(SystemParameterFactory.getSystemParameter(Env.LDAP_FILTER));
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ENTRYDN)!=null)
			this.setEntryDN(SystemParameterFactory.getSystemParameter(Env.LDAP_ENTRYDN));
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_AUTHENTICATION)!=null)
			this.setAuthentication(SystemParameterFactory.getSystemParameter(Env.LDAP_AUTHENTICATION));
		
        //user mapping initialization
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_STAFF_CODE)!=null){
		    this.setStaffCodeMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_STAFF_CODE));
		    this.mappingString=this.getStaffCodeMapping()+",";
		}   
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_FIRSTNAME)!=null){
			this.setFirstNameMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_FIRSTNAME));
			this.mappingString+=this.getFirstNameMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LASTNAME)!=null){
			this.setLastNameMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LASTNAME));
			this.mappingString+=this.getLastNameMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_FULLNAME)!=null){
			this.setFullNameMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_FULLNAME));
			this.mappingString+=this.getFullNameMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_EMAIL)!=null){
			this.setEmailMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_EMAIL));
			this.mappingString+=this.getEmailMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LOGINNAME)!=null){
			this.setLoginNameMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LOGINNAME));
			this.mappingString+=this.getLoginNameMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LOGINPASSWORD)!=null){
			this.setLoginPasswordMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LOGINPASSWORD));
			this.mappingString+=this.getLoginPasswordMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_MAXATTEMPT)!=null){			
			this.setMaxAttemptMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_MAXATTEMPT));
			this.mappingString+=this.getMaxAttemptMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_EXPIRYDAY)!=null){
			this.setExpiryDayMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_EXPIRYDAY));
			this.mappingString+=this.getExpiryDayMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_STATUS)!=null){
			this.setStatusMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_STATUS));
			this.mappingString+=this.getStatusMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_PREFERENCE)!=null){
			this.setPreferenceMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_PREFERENCE));
			this.mappingString+=this.getPreferenceMapping()+",";
		}	
		if(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LANGUAGE)!=null){
			this.setLanguageMapping(SystemParameterFactory.getSystemParameter(Env.LDAP_ACCOUNT_LANGUAGE));
			this.mappingString+=this.getLanguageMapping();
		}	
	}
	
	 // Initial context implementation to use.	 
	private String initctx ="com.sun.jndi.ldap.LdapCtxFactory";
	
	//  Host name and port number of LDAP server	 
	private String service ="";//"ldap://localhost:389"; NT Active directory ,the port is 389,URL like this --> ldap://blr03srv1.rsa.com:389; 
	
	//  DN of directory manager entry. 
	//  This entry should have write access to the entire directory.	 
	private String mgr_DN = "";//"cn=root, dc=example, dc=com";When NT Active Directory like this -->CN=Administrator,CN=Users,DC=rsa,DC=com
	
	//	  Password for manager DN.	 
	private String mgr_PW ="";// "secret";
	
	//    Subtree to search	 
	private String searchbase ="";// "ou=addressbook, dc=example, dc=com";
	
	//  Filter to use when searching.  This one searches for all entries with the
	//  surname (last name) of "Jensen".	 
	private String filter = "";//"(sn=Jensen)";

	private String entryDN="";
	
	private String authentication="simple";//Its value is one of the following strings:"none", "simple", "strong".
	
	private String staffCodeMapping="";
	private String firstNameMapping="";
	private String lastNameMapping="";
	private String fullNameMapping="";
	private String emailMapping="";
	private String loginNameMapping="";
	private String loginPasswordMapping="";
	private String maxAttemptMapping="";
	private String expiryDayMapping="";
	private String statusMapping="";
	private String preferenceMapping="";
	private String languageMapping="";
	
	private String mappingString="";
	
	public String getStaffCodeMapping(){
		return staffCodeMapping;
	}
	public void setStaffCodeMapping(String mapping){
		this.staffCodeMapping=mapping;
	}
	public String getLanguageMapping(){
		return languageMapping;
	}
	public void setLanguageMapping(String mapping){
		this.languageMapping=mapping;
	}
	public String getPreferenceMapping(){
		return preferenceMapping;
	}
	public void setPreferenceMapping(String mapping){
		this.preferenceMapping=mapping;
	}
	public String getStatusMapping(){
		return statusMapping;
	}
	public void setStatusMapping(String mapping){
		this.statusMapping=mapping;
	}
	public String getExpiryDayMapping(){
		return expiryDayMapping;
	}
	public void setExpiryDayMapping(String mapping){
		this.expiryDayMapping=mapping;
	}
	public String getMaxAttemptMapping(){
		return maxAttemptMapping;
	}
	public void setMaxAttemptMapping(String mapping){
		this.maxAttemptMapping=mapping;
	}
	public String getLoginPasswordMapping(){
		return loginPasswordMapping;
	}
	public void setLoginPasswordMapping(String mapping){
		this.loginPasswordMapping=mapping;
	}
	public String getLoginNameMapping(){
		return loginNameMapping;
	}
	public void setLoginNameMapping(String mapping){
		this.loginNameMapping=mapping;
	}
	public String getEmailMapping(){
		return emailMapping;
	}
	public void setEmailMapping(String mapping){
		this.emailMapping=mapping;
	}
	
	public String getFullNameMapping(){
		return fullNameMapping;
	}
	public void setFullNameMapping(String mapping){
		this.fullNameMapping=mapping;
	}
	public String getLastNameMapping(){
		return lastNameMapping;
	}
	public void setLastNameMapping(String mapping){
		this.lastNameMapping=mapping;
	}
	public String getFirstNameMapping(){
		return firstNameMapping;
	}
	public void setFirstNameMapping(String mapping){
		this.firstNameMapping=mapping;
	}
	public String getInitctx(){
		return initctx;
	}
	public void setInitctx(String initctx){
		this.initctx=initctx;
	}
	
	public String getService(){
		return service;
	}
	public void setService(String service){
		this.service=service;
	}
	
	public String getMgr_DN(){
		return mgr_DN;
	}
	public void setMgr_DN(String DN){
		mgr_DN=DN;
	}
	
	public String getMgr_PW(){
		return mgr_PW;
	}
	public void setMgr_PW(String mgr_PW){
		this.mgr_PW=mgr_PW;
	}
	
	public String getSearchbase(){
		return searchbase;
	}
	public void setSearchbase(String searchbase){
		this.searchbase=searchbase;
	}	
	public String getFilter(){
		return filter;
	}
	public void setFilter(String filer){
		this.filter=filer;
	}
	public String getEntryDN(){
		return entryDN;
	}
	public void setEntryDN(String entry){
		this.entryDN=entry;
	}
	public String getMappingString(){
		return mappingString;
	}
	public void setMappingString(String str){
		this.mappingString=str;
	}
	public String getAuthentication(){
		return authentication;
	}
	public void setAuthentication(String auth){
		this.authentication=auth;
	}
	
	public boolean voididateMapping(){
		boolean isError = true;
		isError = //Utility.isEmpty(this.staffCodeMapping.trim())||
		          Utility.isEmpty(this.firstNameMapping.trim())||
		          Utility.isEmpty(this.lastNameMapping.trim())||
		          //Utility.isEmpty(this.fullNameMapping.trim())||
		          Utility.isEmpty(this.loginNameMapping.trim());
		return !isError;
	}
}